'use strict';

/**
 * @ngdoc service
 * @name jgappApp.UserInfo
 * @description
 * # UserInfo
 * Service in the jgappApp.
 */
angular.module('jgappApp')
    .factory('UserInfo', function ($http, openApi, Util, $q) {
        // AngularJS will instantiate a singleton by calling "new" on this function
        var UserInfo = {}
        UserInfo.getUseinfo = function () {
            var defer = $q.defer();
            $http.post(openApi.userInfo)
                .success(function (data) {
                    defer.resolve(data);
                }).error(function () {
                    defer.reject("获取用户信息出错");
                });
            return defer.promise;
        }
        return UserInfo
    }).factory('ContactInfo', function (DataService, openApi, localStorageService, $q, $timeout) {
        // AngularJS will instantiate a singleton by calling "new" on this function
        var ContactInfo = {}
        ContactInfo.getData = function () {
            var defer = $q.defer();
            if (!ContactInfo.data) {
                DataService.getData(openApi.addressbookTree).then(function (data) {
                    ContactInfo.data=data
                    defer.resolve(data);
                })
            } else {
                $timeout(function () {
                    defer.resolve(ContactInfo.data);
                }, 100)
            }
            return defer.promise;
        }
        return ContactInfo
    });
